package com.ytjj.qmyx.mall.amqp.consumer;

import com.rabbitmq.client.Channel;
import com.ytjj.common.constants.QueueConstants;
import com.ytjj.common.dto.mqdto.PrepaidRefillDto;
import com.ytjj.qmyx.mall.service.RechargeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * amqp消息接收
 *
 */
@Component
@Slf4j
public class RechargeListener {

    @Resource
    private RechargeService rechargeService;

    @Transactional(rollbackFor = Exception.class)
    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.RECHARGE_QUEUE, durable = "true"))
    public void recharge(PrepaidRefillDto o, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
        log.info("充值消息：" + o+"\n\n");
        rechargeService.mqRecharge(o.getOrderNo(), o.getOperators());
    }
}
